package cn.swing.his.finance.webapi.controller;

import cn.swing.his.common.web.JsonPage;
import cn.swing.his.common.web.JsonResult;
import cn.swing.his.finance.service.IFinanceFormService;
import cn.swing.his.finance.webapi.service.impl.FinanceFormServiceImpl;
import cn.swing.his.pojo.finance.dto.AddFinanceFormDTO;
import cn.swing.his.pojo.finance.vo.FinanceFormVO;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/finance/form")
@Api(tags = "财务申请表模块")
@Slf4j
public class FinanceFormController {
    @Autowired
    private IFinanceFormService financeFormService;

    /*获取当前所有提交的表单*/
    @ApiOperation("获取所有表单")
    @PostMapping("/list")
    public JsonResult<JsonPage<FinanceFormVO>> pageFinanceForm(Integer pageNum,Integer pageSize,Integer index){
        log.info("pageNum:{}",pageNum);
        log.info("pageSize:{}",pageSize);
        JsonPage<FinanceFormVO> jsonPage=financeFormService.financeFormList(pageNum, pageSize,index);
        return JsonResult.ok("成功",jsonPage);
    }
    @ApiOperation("修改提交申请表状态")
    @GetMapping("/audit")
    @ApiImplicitParam(value = "id",name = "id",example = "1")
    public JsonResult<Void> updateFinanceFormState(Integer id){
        financeFormService.updateFinanceFormState(id);
        return JsonResult.ok();
    }

    @ApiOperation("新增申请表单")
    @PostMapping("/insertFinanceForm")
//    @ApiImplicitParams(
//            @ApiImplicitParam(value = "名字",name = "name",example = "药品购买"),
//            @ApiImplicitParam(value = "科室名",name = "roomName",example = "内科"),
//            @ApiImplicitParam(value = "医生id",name = "doctorId",example = "103"),
//            @ApiImplicitParam(value = "描述",name = "description",example = "药品购买"),
//            @ApiImplicitParam(value = "预计金额",name = "planPrice",example = "10000"),
//            @ApiImplicitParam(value = "数量",name = "num",example = "1000")
//    )
    public JsonResult<Void> insertFinanceForm(AddFinanceFormDTO addFinanceFormDTO){
        financeFormService.insertFinanceForm(addFinanceFormDTO);
        return JsonResult.ok();
    }

    /*批量审批*/
    @ApiOperation("批量审批")
    @GetMapping("/batch")
    public JsonResult<Void> batchFinanceForm(Integer[] ids){
        for (Integer id:ids) {
            financeFormService.updateBatchFinanceFormState(id);
        }
        return JsonResult.ok();
    }
}
